package blink.guimodel;

import java.util.ArrayList;
import java.util.List;

import javax.swing.AbstractListModel;

import blink.model.Experiment;
import blink.model.Task;

public class TaskXpListModel<Task> extends AbstractListModel<Task> {

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	private List<Task> list = new ArrayList<Task>();
	private Experiment model;

	@Override
	public Task getElementAt(int arg0) {
		return (Task) model.getTasks().get(arg0);
	}

	@Override
	public int getSize() {
		return model.getTasks().size();
	}

	public void addTask(Task t) {
		int size = getSize();
		model.addTask((blink.model.Task) t, 1);
		this.fireIntervalAdded(this, size, size);
	}

	public void removeTask(int idx) {
		if (idx != -1) {
			model.removeTask(idx);
			this.fireIntervalRemoved(this, idx, idx);
		}
	}

	public void setModel(Experiment model) {
		this.model = model;
	}

	public void fireContentsChanged(int selectedIndex) {
		fireContentsChanged(this, selectedIndex, selectedIndex);
	}
}
